//
//  NSArray+YWK.m
//  YWKUser
//
//  Created by  WangDan on 16/5/3.
//  Copyright © 2016年 iCareTech. All rights reserved.
//

#import "NSArray+YWK.h"

@implementation NSArray (YWK)

- (NSArray *)ascendingSortFloatArray{
    
    NSComparator finderSort = ^(id string1,id string2){
        
        if ([string1 floatValue] > [string2 floatValue]) {
            return (NSComparisonResult)NSOrderedDescending;
        }else if ([string1 integerValue] < [string2 integerValue]){
            return (NSComparisonResult)NSOrderedAscending;
        }else
            return (NSComparisonResult)NSOrderedSame;
    };
    
    return [self sortedArrayUsingComparator:finderSort];
}

- (NSArray *)ascendingSortStringArray{
    
    NSStringCompareOptions comparisonOptions =  NSCaseInsensitiveSearch
                                                | NSNumericSearch
                                                | NSWidthInsensitiveSearch
                                                | NSForcedOrderingSearch;
    
    NSComparator sort = ^(NSString *obj1,NSString *obj2){
        
        NSRange range = NSMakeRange(0, obj1.length);
        return [obj1 compare:obj2 options:comparisonOptions range:range];
    };
    
    return [self sortedArrayUsingComparator:sort];
}

- (NSArray *)moveHeadSpaceStringToTail{

    NSMutableArray *arrayM = self.mutableCopy;

    int spaceIndex = -1;
    
    for (int i = 0; i < arrayM.count; i++) {
        
        NSRange spaceRange = [arrayM[i] rangeOfString:@" "];
        
        if (spaceRange.location == NSNotFound) {
            break;
        }
        
        spaceIndex = i;
    }
    
    NSArray *arraySpace = [arrayM subarrayWithRange:NSMakeRange(0, spaceIndex + 1)];
    [arrayM removeObjectsInRange:NSMakeRange(0, spaceIndex + 1)];
    [arrayM addObjectsFromArray:arraySpace];
    
    return arrayM.copy;
}

@end
